package io.dshubs.archives.controller;


import io.dshubs.archives.entity.ArchiveBaseStore;
import io.dshubs.archives.entity.ArchiveTransferList;
import io.dshubs.archives.service.ArchiveBaseInfoService;
import io.dshubs.archives.service.ArchiveBaseStoreService;
import io.dshubs.archives.service.ArchiveTransferListService;
import io.dshubs.commons.log.annotation.LogOperation;
import io.dshubs.commons.tools.constant.Constant;
import io.dshubs.commons.tools.page.PageData;
import io.dshubs.commons.tools.utils.Result;
import io.dshubs.commons.tools.validator.ValidatorUtils;
import io.dshubs.commons.tools.validator.group.AddGroup;
import io.dshubs.commons.tools.validator.group.DefaultGroup;
import io.dshubs.commons.tools.validator.group.UpdateGroup;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 库存表 前端控制器
 * </p>
 *
 * @author tan
 * @since 2021-08-26
 */
@Api(tags = "库存表")
@RestController
@RequestMapping("/base-store")
public class ArchiveBaseStoreController {
    @Autowired
    private ArchiveBaseStoreService archiveBaseStoreService;

    @GetMapping("page")
    @ApiOperation("库存表:page")
    @LogOperation("库存管理:/warehouse/store:/img/icon-库存管理.png:page")
    @ApiImplicitParams({
            @ApiImplicitParam(name = Constant.PAGE, value = "当前页码，从1开始", paramType = "query", required = true, dataType="int") ,
            @ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataType="int") ,
            @ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataType="String") ,
            @ApiImplicitParam(name = Constant.ORDER, value = "排序方式，可选值(asc、desc)", paramType = "query", dataType="String") ,
            @ApiImplicitParam(name = "fileNumber", value = "档号", paramType = "query", dataType="String")
    })
    public Result<PageData<ArchiveBaseStore>> page(@ApiIgnore @RequestParam Map<String, Object> params){
        return new Result<PageData<ArchiveBaseStore>>().ok(archiveBaseStoreService.page(params));
    }

    @GetMapping("{id}")
    @ApiOperation("详情")
    @LogOperation("库存表:get")
    public Result<ArchiveBaseStore> get(@PathVariable("id") Long id){
        return new Result<ArchiveBaseStore>().ok(archiveBaseStoreService.selectById(id));
    }

    @PostMapping
    @ApiOperation("保存")
    @LogOperation("库存表:save")
    public Result save(@RequestBody ArchiveBaseStore archiveBaseStore){
        //效验数据
        ValidatorUtils.validateEntity(archiveBaseStore, AddGroup.class, DefaultGroup.class);

        archiveBaseStoreService.insert(archiveBaseStore);
        return new Result();
    }

    @PutMapping
    @ApiOperation("修改")
    @LogOperation("库存表:update")
    public Result update(@RequestBody ArchiveBaseStore archiveBaseStore){
        //效验数据
        ValidatorUtils.validateEntity(archiveBaseStore, UpdateGroup.class, DefaultGroup.class);

        archiveBaseStoreService.updateById(archiveBaseStore);

        return new Result();
    }

    @DeleteMapping()
    @ApiOperation("删除")
    @LogOperation("库存表:delete")
    public Result delete(@RequestBody @NotNull(message = "批量删除id不能为空") List<Long> ids){
        archiveBaseStoreService.deleteBatchIds(ids);
        return new Result();
    }
}
